<?php defined('SYSPATH') or die('No direct script access.'); ?>
<?php echo "<?php defined('SYSPATH') or die('No direct script access.');?>" ?>

<?php echo '<?php if ($errors): ?>' ?>
<p class="message">Some errors were encountered, please check the details you entered.</p>
<ul class="errors">
<?php echo '<?php foreach ($errors as $message): ?>' ?>
<li><?php echo '<?php echo $message ?>' ?></li>
<?php echo '<?php endforeach ?>'?>
</ul>
<?php echo '<?php endif ?>' ?>

<?php echo "<?php echo form::open(null, array('id'=>'edit_form'))?>" ?>
<dl>
    <?php foreach ($fields as $f) : ?>
    <dt>  
        <?php echo "<?php echo Form::label('". $f['name'] . "', '" . ucwords($f['name']) . "') ?>" ?>
    </dt>
    <dd>
        <?php if ($f['ref'] != ''): ?>
        <?php echo "<?php echo Form::select('".$f['name']."', array('' => '----')+ORM::factory('".$f['ref']."')->find_all()->as_array('id', 'name'), $".$model."->".$f['name'].") ?>" ?>
        <?php elseif ($f['type'] == 'text'): ?>
        <?php echo "<?php echo Form::textarea ('".$f['name']."', $".$model."->".$f['name'].") ?>" ?>
        <?php else: ?>
        <?php echo "<?php echo Form::input('".$f['name']."', $".$model."->".$f['name'].") ?>" ?>
        <?php endif; ?>
    </dd>
    <?php endforeach; ?>
    <dt>&nbsp;</dt>
    <dd>
        <?php echo "<?php echo Form::submit('btn_save', 'Save') ?>" ?>
        <input type="button" value="Cancel"
               onclick="location = '<?php echo "<?php echo Url::site('$model') ?>" ?>';" />
        
    </dd>
</dl>
<?php echo "<?php echo form::close() ?>" ?>


<?php echo "<?php echo $".$model."->validate()->get_jsvalidate('#edit_form', '".$model."_edit', false) ?>"?>